package com.fany.filesearcher;

import android.app.ProgressDialog;
import android.os.Handler;
import android.os.Message;
import com.fany.constants.StringResources;

public class FileSearchProgressHandler extends Handler
{
    private final Runnable runnable;
    public ProgressDialog progressDialog;
    private SQLiteFileRecorder _recorder;

    public FileSearchProgressHandler(SQLiteFileRecorder recorder, Runnable runnable)
    {
        this._recorder = recorder;
        this.runnable = runnable;
    }

    @Override
    public void handleMessage(Message msg)
    {
        if (progressDialog.isShowing())
        {
            if (FileScanner.instance().isInterrupted())
            {
                return;
            }
            int count = FileScanner.instance().getScannedCount();
            String message = String.format(StringResources.scanFileHint, count);
            message += "\n";
            count = _recorder.getRecordCount();
            message += String.format(StringResources.loadFileHint + "", count);
            progressDialog.setMessage(message);
        }
        this.postDelayed(runnable, 500);
    }
}